package com.shop.model.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.model.entity.BulkTb;
import com.shop.model.entity.Classifys;
import com.shop.model.entity.GoodsTb;
import com.shop.model.entity.Species;
import com.shop.model.mapper.GoodsTbMapper;
import com.shop.model.service.IClassifysService;
import com.shop.model.service.IGoodsTbService;
import com.shop.model.service.ISpeciesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;

import java.time.LocalDate;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shop
 * @since 2018-12-04
 */
@Controller
public class ClassifysController {
    @Autowired
    private IClassifysService iClassifysService;
    @Autowired
    private ISpeciesService iSpeciesService;
    @Autowired
    private IGoodsTbService iGoodsTbService;
    @Autowired
    private GoodsTbMapper goodsTbMapper;
    /**
     * @author 叶虽/显示总分类数据
     * @param
     * @return
     */
    @RequestMapping("/show")
    public String showAllMuen(Model model , HttpServletRequest request, Species species ){
        //查询所有总类名
        List<Classifys> classifysLists = iClassifysService.list();
        //查询所有分类名

        List<Species> speciesList = iSpeciesService.list();
            model.addAttribute("speciesList",speciesList);
            model.addAttribute("classify",classifysLists);
        return "commodity";
    }

    /**
     * @author 叶虽/分页显示所有商品
     * @param page
     * @return
     */
    @ResponseBody()
    @RequestMapping("/classifysController")
    private Object classifysController(String page){
        Integer integer = Integer.valueOf(page);
        IPage iPage = goodsTbMapper.selectPage(new Page(integer, 6), new QueryWrapper<GoodsTb>());
        List<GoodsTb> goodsTbList = iPage.getRecords();
        return goodsTbList;
    }


}

